#include "../Include/GcpFrameServer.h"
#include "../Include/GcpClientEvent.h"

CGcpFrameServer::CGcpFrameServer(CEventEngine *pListenEngine)
    : CFrameServer(pListenEngine)
{
    m_pFactory = NULL;
}

CGcpFrameServer::~CGcpFrameServer()
{
}

Bool CGcpFrameServer::Start(const CSocketAddr &address, const std::vector<CEventEngine *> &vecAsyncIo, CThreadPool *pWorkPool, IGcpHandlerFactory *pFactory)
{
    m_pFactory = pFactory;
    return CFrameServer::Start(address, vecAsyncIo, pWorkPool);
}

CClientEvent* CGcpFrameServer::CreateClientEvent(Int32 nClientFD, const CSocketAddr &addr, CEventEngine *pEngine, IMessageDispatcher *pDispatcher)
{
    CGcpClientEvent *pClientEvent = new CGcpClientEvent(nClientFD, addr, pEngine, pDispatcher);
    CGcpProxyPtr spProxy(new CGcpProxy(pClientEvent));

    IGcpHandler *pHandler = m_pFactory->Create(spProxy);
    pClientEvent->SetHandler(pHandler);
    pClientEvent->SetProxy(spProxy);

    return pClientEvent;
}
